{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "aa5975ae",
   "metadata": {},
   "outputs": [],
   "source": [
    "def func(xold):\n",
    "    return 3-7/(xold+3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "bd49bc46",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "第 1 次 误差为 0.25  目前new为 1.25\n",
      "第 2 次 误差为 0.10294117647058831  目前new为 1.3529411764705883\n",
      "第 3 次 误差为 0.038950715421303794  目前new为 1.391891891891892\n",
      "第 4 次 误差为 0.014261954261954202  目前new为 1.4061538461538463\n",
      "第 5 次 误差为 0.005159003008164964  目前new为 1.4113128491620113\n",
      "第 6 次 误差为 0.0018579597662775615  目前new为 1.4131708089282888\n",
      "第 7 次 误差为 0.0006680604310627114  目前new为 1.4138388693593515\n",
      "第 8 次 误差为 0.00024007480110488366  目前new为 1.4140789441604564\n",
      "第 9 次 误差为 8.625574822418436e-05  目前new为 1.4141651999086806\n",
      "第 10 次 误差为 3.098827548275729e-05  目前new为 1.4141961881841634\n",
      "第 11 次 误差为 1.1132564863070016e-05  目前new为 1.4142073207490264\n",
      "第 12 次 误差为 3.999345426608514e-06  目前new为 1.414211320094453\n",
      "第 13 次 误差为 1.436749680561178e-06  目前new为 1.4142127568441336\n",
      "第 14 次 误差为 5.161462395264493e-07  目前new为 1.4142132729903731\n",
      "第 15 次 误差为 1.8542326940540477e-07  目前new为 1.4142134584136425\n",
      "第 16 次 误差为 6.661248419526089e-08  目前new为 1.4142135250261267\n",
      "循环次数为 16 终值为 1.4142135250261267\n"
     ]
    }
   ],
   "source": [
    "xold=1\n",
    "new=1\n",
    "i=0\n",
    "listNew=[]\n",
    "listI=[]\n",
    "listD=[]\n",
    "while True:\n",
    "    xnew=func(xold)\n",
    "    listNew.append(xnew)\n",
    "    d=abs(xnew-xold)\n",
    "    xold=xnew\n",
    "    i=i+1\n",
    "    listI.append(i)\n",
    "    listD.append(d)\n",
    "    print('第',i,'次 误差为',d,' 目前new为',xnew)\n",
    "    if d<0.0000001:\n",
    "        break\n",
    "print('循环次数为',i,'终值为',xold)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "57186b21",
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "f1acc7b2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 3.0 1e+100\n",
      "2 1.8333333333333333 1.1666666666666667\n",
      "3 1.5517241379310345 0.2816091954022988\n",
      "4 1.4621212121212122 0.08960292580982232\n",
      "5 1.431239388794567 0.03088182332664524\n",
      "6 1.4203065134099617 0.01093287538460519\n",
      "7 1.4163994105920084 0.003907102817953367\n",
      "8 1.414998429894803 0.0014009806972052896\n",
      "9 1.4144954723875653 0.0005029575072377224\n",
      "10 1.4143148308148399 0.00018064157272545955\n",
      "11 1.4142499417723073 6.488904253254546e-05\n",
      "12 1.4142266314015008 2.331037080649523e-05\n",
      "13 1.4142182573490738 8.374052427040368e-06\n",
      "14 1.4142152490203783 3.0083286954862842e-06\n",
      "15 1.4142141682933405 1.0807270378609957e-06\n",
      "16 1.4142137800471977 3.882461427906492e-07\n",
      "17 1.4142136405715369 1.3947566079863805e-07\n",
      "18 1.4142135904655344 5.010600245825003e-08\n",
      "19 1.4142135724651779 1.8000356538649953e-08\n",
      "20 1.4142135659986306 6.466547297634406e-09\n",
      "21 1.4142135636755524 2.3230781742711315e-09\n",
      "22 1.414213562840997 8.345553137445449e-10\n",
      "23 1.4142135625411867 2.998103987295053e-10\n",
      "24 1.4142135624334813 1.0770540015414554e-10\n",
      "25 1.4142135623947885 3.869282672042118e-11\n",
      "26 1.4142135623808885 1.389999226830696e-11\n",
      "27 1.414213562375895 4.993561120159029e-12\n",
      "28 1.414213562374101 1.793898363189328e-12\n",
      "29 1.4142135623734564 6.445954880973659e-13\n",
      "30 1.4142135623732248 2.3159252293680765e-13\n",
      "31 1.4142135623731416 8.326672684688674e-14\n",
      "32 1.414213562373112 2.9531932455029164e-14\n",
      "33 1.4142135623731011 1.0880185641326534e-14\n",
      "34 1.4142135623730971 3.9968028886505635e-15\n",
      "35 1.414213562373096 1.1102230246251565e-15\n",
      "36 1.4142135623730954 6.661338147750939e-16\n",
      "37 1.4142135623730954 0.0\n",
      "循环次数为 37 终值为 1.4142135623730954\n"
     ]
    }
   ],
   "source": [
    "xold=10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n",
    "new=1\n",
    "i=0\n",
    "x=\n",
    "\n",
    "while True:\n",
    "    xnew=func(xold)\n",
    "    d=abs(xnew-xold)\n",
    "    xold=xnew\n",
    "    i=i+1\n",
    "    print(i,xnew,d)\n",
    "    if d<0.0000000000000001:\n",
    "        break\n",
    "print('循环次数为',i,'终值为',xold)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "10634cdd",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
